# with open('demo.csv', encoding='utf-8') as f:
#     # str = f.readline()  # 一行内容
#     # str = str.replace('\n', '')
#     # print(str)
#     # arr = str.split(',')  # 字符串的数组
#     # print(arr)
#     lines = []
#     for line in f.readlines():
#         line = line.replace('\n', '')  # 一行+\n
#         arr = line.split(',')
#         lines.append(arr)
#     print(lines)  # 表格的二维列表表示

# ============================
lines = []  # 原数据
with open('demo.csv', encoding='utf-8') as f:
    for line in f.readlines():
        line = line.replace('\n', '')  # 一行+\n
        arr = line.split(',')
        lines.append(arr)

lines[0].append('总分')  # 添加总分字段
# 处理第二行到最后一行（数据行），每行计算总分再加进来
for i in range(1, len(lines)):  # line是每一行的列表
    # print(lines[i])  # 每一数据行
    total = 0
    for j in range(1, len(lines[i])):
        total += int(lines[i][j])  # 读取的内容都是字符串
    # print(f'{lines[i][0]}的总分{total}')
    lines[i].append(str(total))  # 追加总分到当前行
print(lines)  # 加了新数据的表格

# 根据新的二位列表写成一个表格.csv
with open('score.csv', 'w', encoding='utf-8') as f:
   for line in lines:  # line是一行的列表数据
       # ','.join(line)  # 根据列表元素和分割字符拼接成一个字符串
       f.write(','.join(line) + '\n')